from math import *

TrainNumSum = 1596


#input
TrainTime = int(input())

NowChange = int(input())

TestDataA = list(map(float,input().split(" ")))
TestDataB = list(map(float,input().split(" ")))
TestDataC = list(map(float,input().split(" ")))
TestDataD = list(map(float,input().split(" ")))
TestDataX1 = list(map(float,input().split(" ")))
TestDataX2 = list(map(float,input().split(" ")))
TestDataX3 = list(map(float,input().split(" ")))

TrainNum = list(map(float,input().split(" ")))
ChangeNum = list(map(float,input().split(" ")))

if(len(TrainNum) == 1):
    TrainNum = []
    for i in range(TrainNumSum):
        TrainNum.append(1)

if(len(ChangeNum) == 1):
    ChangeNum = []
    for i in range(TrainNumSum):
        ChangeNum.append(1)
#input end


#开奇数次方根
def pows(a,b):
    d = a/abs(a)
    res = pow(abs(a),1/b)
    res *= d
    return res
#开奇数次方根 end


#计算方程的解
def cac(a,b,c,d):
    global TrainNum
    
    sum = 0

    Cac1 = []
    for i in range(12):
        Cac1.append(0)
    for i in range(12):
        for j in range(4):
            Cac1[i] += TrainNum[sum]*(a**j)
            sum += 1
            Cac1[i] += TrainNum[sum]*(b**j)
            sum += 1
            Cac1[i] += TrainNum[sum]*(c**j)
            sum += 1
            Cac1[i] += TrainNum[sum]*(d**j)
            sum += 1
    

    Cac2 = []
    for i in range(36):
        Cac2.append(0)
    for i in range(36):
        for j in range(12):
            Cac2[i] += TrainNum[sum]*pows(Cac1[j],5)
            sum += 1
            Cac2[i] += TrainNum[sum]*pows(Cac1[j],3)
            sum += 1
            Cac2[i] += TrainNum[sum]*Cac1[j]
            sum += 1
    
    Res = [0,0,0]
    for i in range(3):
        for j in range(36):
            Res[i] += TrainNum[sum]*Cac2[j]
            sum += 1
    
    Res.sort()

    return Res
#计算方程的解 end


#计算方差
def cacDev():
    Dres = 0.0
    for i in range(len(TestDataA)):
        res = cac(TestDataA[i],TestDataB[i],TestDataC[i],TestDataD[i])
        Dres += (res[0]-TestDataX1[i])**2
        Dres += (res[1]-TestDataX2[i])**2
        Dres += (res[2]-TestDataX3[i])**2
    
    return Dres
#计算方差 end


#更改函数
def change(BefDeviation):
    global TrainNum,ChangeNum,NowChange
    LTrainNum = TrainNum[NowChange]
    TrainNum[NowChange] += ChangeNum[NowChange]

    AftDeviation = cacDev()

    if(BefDeviation > AftDeviation):
        ChangeNum[NowChange] *= 2
        return AftDeviation
    else:
        ChangeNum[NowChange] *= -0.5
        TrainNum[NowChange] = LTrainNum
        return BefDeviation
#更改函数 end


#主函数
def main():
    global TrainTime,NowChange

    Deviation = cacDev()
    for i in range(TrainTime):
        Deviation = change(Deviation)
        NowChange = (NowChange+1)%TrainNumSum
        if(i%10 == 0):
            print("[",i,"] ",Deviation)
    
    print()
    print("========Result========")
    print(Deviation)
    for i in range(TrainNumSum):
        print(str(TrainNum[i]),end=" ")
    
    print()
    for i in range(TrainNumSum):
        print(str(ChangeNum[i]),end=" ")
#主函数 end

main()